# This is a sample Python script.
import serial
import pyaudio

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


#def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
#    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    # print_hi('PyCharm')
    port = "COM3"
    bps = 1000000
    ser = serial.Serial(port, bps)

    p = pyaudio.PyAudio()

    # open stream (2)
    stream = p.open(format= pyaudio.paInt8,  #p.get_format_from_width(1),
#    stream = p.open(format= p.get_format_from_width(1),
                                  channels=1,
                                  rate=48000,
                                  output=True)

    while True:
        stream.write(ser.read())
#        print(ser.read().hex())

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
